package week02

// 154. 寻找旋转排序数组中的最小值 II
// https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/

func findMin(nums []int) int {
	var left, right = 0, len(nums)-1
	for left < right {
		var mid = (right - left) >> 1 + left
		if nums[mid] < nums[right] {
			right = mid
		} else if nums[mid] > nums[right] {
			left = mid + 1
		} else {
			right-- // 一定是right--，相等的时候，最小值一定在左边
		}
	}
	return nums[left]
}